fix: use active product version [APIAPEX-2731]#83
Closed
DKVON-prog wants to merge 6 commits into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes the vcr init flow so that it selects a product template's currently active (live) version instead of the most recently created ProductVersion. Previously, picking the newest version by created_at could surface a draft/non-live version, breaking template downloads. The datastore method (and its consumers/mocks/tests) is renamed accordingly.
Changes:
- Rename
GetLatestProductVersionByID→GetActiveProductVersionByIDacross the datastore client, factory interface, mocks, and call site invcr/init, and update the corresponding user-facing spinner/error messages. - Reimplement the lookup as two sequential GraphQL queries: fetch the product's
active_version_idviaProducts_by_pk, then resolve that version viaProductVersions_by_pk. - Expand unit tests in
init_test.goanddatastore_test.goto cover the new flow, including missing product, emptyactive_version_id, missing version row, and a regression case ensuring drafts are not returned.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/api/datastore.go | Replaces the latest-version GraphQL query with a two-step active-version lookup and renames associated types/method. |
| pkg/api/datastore_test.go | Reworks the test harness to feed sequenced mock responses and adds new-failure / regression cases. |
| pkg/cmdutil/factory.go | Renames the method on DatastoreInterface. |
| testutil/mocks/factory.go | Regenerated mock reflecting the renamed method. |
| vcr/init/init.go | Calls the renamed method and updates spinner / wrapped-error wording. |
| vcr/init/init_test.go | Renames mock fields and adds an "active version not found" test case. |
Files not reviewed (1)
- testutil/mocks/factory.go: Language not supported
Comment on lines
+379
to
401
| const getVersionQuery = ` | ||
| query MyQuery ($id: uuid!) { | ||
| ProductVersions_by_pk(id: $id) { | ||
| id | ||
| } | ||
| } | ||
| ` | ||
| activeVersionID := resp.Data.Product.ActiveVersionID | ||
| versionReq := GQLRequest{ | ||
| Query: getVersionQuery, | ||
| Variables: getActiveProductVersionByIDParams{ID: activeVersionID}, | ||
| } | ||
| var versionResp getProductVersionByIDResponse | ||
| if err := ds.gqlClient.Do(ctx, versionReq, &versionResp); err != nil { | ||
| return ProductVersion{}, err | ||
| } | ||
| if versionResp.Data.ProductVersion == nil || versionResp.Data.ProductVersion.ID == "" { | ||
| return ProductVersion{}, ErrNotFound | ||
| } | ||
|
|
||
| return *versionResp.Data.ProductVersion, nil | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.